package com.whmall.service.crm.module.companyuser.impl;

import com.whmall.component.common.ObjectConverter;
import com.whmall.component.enumeration.UserPageSourceEnum;
import com.whmall.service.crm.entity.dto.companyuser.CreateOrUpdateCompanyUserReqDTO;
import com.whmall.service.crm.module.companyuser.entity.CompanyUserDO;
import org.springframework.stereotype.Component;

/**
 * CreateOrUpdateCompanyUserReqDTO -> CompanyUserDO 转换器
 *
 * @author alex
 * @since 2020/7/31
 */
@Component
public class CoU2CompanyUserConverter
        implements ObjectConverter<CreateOrUpdateCompanyUserReqDTO, CompanyUserDO> {

    @Override
    public CompanyUserDO fillProperties(CreateOrUpdateCompanyUserReqDTO source, CompanyUserDO dest) {
        if (null == dest) {
            dest = new CompanyUserDO();
        }

        dest.setName(source.getName());
        dest.setMobile(source.getMobile());
        dest.setEmail(source.getEmail());
        dest.setTel(source.getTel());
        dest.setQq(source.getQq());
        dest.setFax(source.getFax());
        dest.setIsCustomer(source.getIsCustomer());
        dest.setIsSupplier(source.getIsSupplier());
        dest.setGender(source.getGender());
        dest.setBirthday(source.getBirthday());
        dest.setPageSource(source.getPageSource());
        dest.setExpressCompany(source.getExpressCompany());
        dest.setIsPrecursor(UserPageSourceEnum.PC_PRECURSOR.getValue().equals(source.getPageSource()) ? 1 : 0);

        return dest;
    }
}
